chrome.extension.onRequest.addListener(function (request, sender, sendResponse) {
	// chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
	// console.log("收到来自content-script的消息：");
	// console.log(request, sender, sendResponse);

	// chrome.storage.sync.set({ key: 110 }, function () {
	// 	console.log("Value is set to ");
	// });

	if (request["type"] == "localStorage") {
		// sendResponse('我是后台，我已收到你的消息：' + localStorage.getItem('plugin_height'));
		// sendResponse({});
		chrome.storage.sync.get([request["key"]], function (result) {
			var d = {};
			d[request["key"]] = result[request["key"]];
			sendResponse(d);
		});
	}
});
// var enableHosts = [];

chrome.webRequest.onBeforeSendHeaders.addListener(
	function (details) {
		// console.log(details);
		chrome.tabs.sendMessage(details.tabId, Object.assign(details, { cycle: "beforeSendHeaders" }), function () {}); // 向 浏览器 发送信息
		// for (var i = 0; i < details.requestHeaders.length; ++i) {
		//   if (details.requestHeaders[i].name === 'User-Agent') {
		//     details.requestHeaders.splice(i, 1);
		//     break;
		//   }
		// }
		// return {requestHeaders: details.requestHeaders};
	},
	{ urls: ["http://*/*", "https://*/*"], types: ["xmlhttprequest"] },
	// ["blocking", "requestHeaders"]
);

chrome.webRequest.onCompleted.addListener(
	function (details) {
		// console.log(details);
		chrome.tabs.sendMessage(details.tabId, Object.assign(details, { cycle: "completed" }), function () {}); // 向 浏览器 发送信息
	},
	{ urls: ["http://*/*", "https://*/*"], types: ["xmlhttprequest"] },
	// ["blocking", "requestHeaders"]
);
